package proyecto.BusinessLogic;

import java.util.List;

import javax.ejb.Remote;
import javax.ejb.Stateless;
import javax.naming.Context;
import javax.naming.InitialContext;
import javax.naming.NamingException;

import proyecto.DataAccessObject.CentroEducativoDAORemote;
import proyecto.EntityBeans.CentroEducativo;

@Stateless
@Remote(CentroEducativoBLRemote.class)
public class CentroEducativoBL implements CentroEducativoBLRemote {

	CentroEducativoDAORemote centroEducativoDAORemote;
	
	public int save(CentroEducativo centroEducativo) {	
		
		try
		{
			Context context = new InitialContext();
			centroEducativoDAORemote = (CentroEducativoDAORemote) context.lookup("CentroEducativoDAO/remote");
		} catch (NamingException e)
		{
			e.printStackTrace();
			throw new RuntimeException(e);
		}
			
		return centroEducativoDAORemote.save(centroEducativo); //alta de centroEducativo		
		
	}
		
	public CentroEducativo findById(int id) {
		try
		{
			Context context = new InitialContext();
			centroEducativoDAORemote = (CentroEducativoDAORemote) context.lookup("CentroEducativoDAO/remote");
		} catch (NamingException e)
		{
			e.printStackTrace();
			throw new RuntimeException(e);
		}
			
		return centroEducativoDAORemote.findById(id);
		
	}
	
		
	public void merge(CentroEducativo centroEducativo) {
		try
		{
			Context context = new InitialContext();
			centroEducativoDAORemote = (CentroEducativoDAORemote) context.lookup("CentroEducativoDAO/remote");
			centroEducativoDAORemote.merge(centroEducativo);
		} catch (NamingException e)
		{
			e.printStackTrace();
			throw new RuntimeException(e);
		}	
		
	}
	
	public List findByName(String name)
	{	
		try
		{
			Context context = new InitialContext();
			centroEducativoDAORemote = (CentroEducativoDAORemote) context.lookup("CentroEducativoDAO/remote");
		} catch (NamingException e)
		{
			e.printStackTrace();
			throw new RuntimeException(e);
		}
		
	    return centroEducativoDAORemote.findByName(name);
	}
	
	public List findAll() {		
		try
		{
			Context context = new InitialContext();
			centroEducativoDAORemote = (CentroEducativoDAORemote) context.lookup("CentroEducativoDAO/remote");
		} catch (NamingException e)
		{
			e.printStackTrace();
			throw new RuntimeException(e);
		}
		
		return centroEducativoDAORemote.findAll();
	}
	
	public List findByIdList(int id)
	{	     
		try
		{
			Context context = new InitialContext();
			centroEducativoDAORemote = (CentroEducativoDAORemote) context.lookup("CentroEducativoDAO/remote");
		} catch (NamingException e)
		{
			e.printStackTrace();
			throw new RuntimeException(e);
		}
		
	    return centroEducativoDAORemote.findByIdList(id);
	}
	
		
	public void remove(int idCurso){	
		try
		{
			Context context = new InitialContext();
			centroEducativoDAORemote = (CentroEducativoDAORemote) context.lookup("CentroEducativoDAO/remote");
		} catch (NamingException e)
		{
			e.printStackTrace();
			throw new RuntimeException(e);
		}
		
		centroEducativoDAORemote.remove(idCurso);
	}
	
	public void refresh(CentroEducativo centroEducativo){
		try
		{
			Context context = new InitialContext();
			centroEducativoDAORemote = (CentroEducativoDAORemote) context.lookup("CentroEducativoDAO/remote");
		} catch (NamingException e)
		{
			e.printStackTrace();
			throw new RuntimeException(e);
		}
		
		centroEducativoDAORemote.refresh(centroEducativo);
	}
}
